package gspringboot

import (
	"gitee.com/hongzhaomin/gspring/aware"
	"gitee.com/hongzhaomin/gspring/iface"
	"gitee.com/hongzhaomin/xormplus"
)

var _ iface.BeanPostProcessor = (*XormplusDaoBeanProcessor)(nil)
var _ aware.BeanFactoryAware = (*XormplusDaoBeanProcessor)(nil)

type XormplusDaoBeanProcessor struct {
	iface.AbstractBeanPostProcessor
	aware.Aware

	factory iface.BeanFactory
	logger  iface.GspringLogger
}

func (my *XormplusDaoBeanProcessor) SetBeanFactory(factory iface.BeanFactory) {
	my.factory = factory
	my.logger = factory.GetBeanByName(LoggerBeanName).(iface.GspringLogger)
}

func (my *XormplusDaoBeanProcessor) PostProcessBeforeInitialization(_ string, bean any) any {
	dao, ok := bean.(xormplus.Dao)
	if ok {
		dao.SetLog(my.logger)
	}
	return bean
}
